2020-2021 Sunseeker Telemetry and Lighting System
usci_a_uart_ex3_autoBaudrateDetectionRX.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
62 //******************************************************************************
63 #define BAUD_RATE 9600
64 #define RECEIVE_DATA_COUNT 0x03
65 #define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS 0xAA
66 
68 
69 void main (void)
70 {
71  //Stop WDT
72  WDT_A_hold(WDT_A_BASE);
73 
74  //P3.4,5 = USCI_A0 TXD/RXD
75  GPIO_setAsPeripheralModuleFunctionInputPin(
76  GPIO_PORT_P3,
77  GPIO_PIN4 + GPIO_PIN5
78  );
79 
80  //Initialize UART module in auto baudrate detection multiprocessor mode
81  //Baudrate = 9600, clock freq = 1.048MHz
82  //UCBRx = 6, UCBRFx = 13, UCBRSx = 0, UCOS16 = 1
83  USCI_A_UART_initParam param = {0};
84  param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
85  param.clockPrescalar = 6;
86  param.firstModReg = 13;
87  param.secondModReg = 0;
88  param.parity = USCI_A_UART_NO_PARITY;
89  param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
90  param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
91  param.uartMode = USCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE;
92  param.overSampling = USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
93  if (STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param)){
94  return;
95  }
96 
97  //Enable UART module for operation
98  USCI_A_UART_enable(USCI_A0_BASE);
99 
100  //Put UART to sleep/dormant mode toreceive break/sync first
101  USCI_A_UART_setDormant(USCI_A0_BASE);
102 
103  //Enable Receive Interrupt
104  USCI_A_UART_clearInterrupt(USCI_A0_BASE,
105  USCI_A_UART_RECEIVE_INTERRUPT);
106  USCI_A_UART_enableInterrupt(USCI_A0_BASE,
107  USCI_A_UART_RECEIVE_INTERRUPT);
108 
109  //Enter LPM3, interrupts enabled
110  __bis_SR_register(LPM3_bits + GIE);
111  __no_operation();
112 }
113 
114 //******************************************************************************
115 //
116 //This is the USCI_A0 interrupt vector service routine.
117 //
118 //******************************************************************************
119 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
120 #pragma vector=USCI_A0_VECTOR
121 __interrupt
122 #elif defined(__GNUC__)
123 __attribute__((interrupt(USCI_A0_VECTOR)))
124 #endif
125 void USCI_A0_ISR (void)
126 {
127  switch (__even_in_range(UCA0IV,4)){
128  //Vector 2 - RXIFG
129  case 2:
130 
131  //Receive the data
132  receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
133 
135  if (0x00 == receiveDataCount){
136  //Set to dormant mode to recive break/sync first
137  USCI_A_UART_setDormant(USCI_A0_BASE);
139  } else {
140  //Wake up from dormant mode
141  USCI_A_UART_resetDormant(USCI_A0_BASE);
142  }
143 
144  //Send data back "echo"
145  USCI_A_UART_transmitData(USCI_A0_BASE,
146  receivedData);
147 
148  break;
149  default: break;
150  }
151 }
152 
MPU_initThreeSegmentsParam param
__no_operation()
#define STATUS_FAIL
Definition: hw_memmap.h:23